package com.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSONObject;
import com.web.entity.SysUser;
import com.web.service.SysUserService;

@Controller
@RequestMapping("home")
public class HomeController {

	@Autowired
	private SysUserService sysUserService;

	@RequestMapping("index")
	public String indexTap() {

		return "index";
	}

	@RequestMapping("main")
	public String mainTap() {

		return "manage/main";
	}

	@RequestMapping("testposter")
	public String testposter() {

		return "manage/adminPoster";
	}

	@RequestMapping("login")
	public String loginTap() {

		return "login";
	}

	@RequestMapping("reg")
	public String registerTap() {

		return "register";
	}

	@RequestMapping("income")
	public String incomeTap() {

		return "income";
	}

	@RequestMapping("register")
	public String register(SysUser user) {

		System.out.println("接受注册！");
		String md5Password = DigestUtils.md5DigestAsHex(user.getPassword().getBytes());
		user.setPassword(md5Password);
		System.out.println(md5Password);
		System.out.println(JSONObject.toJSONString(user));
		sysUserService.addUser(user);
		return "login";
	}

}
